// 表单验证规则
export const validatePassword = (rule: any, value: string, callback: any) => {
  if (value === '') {
    callback(new Error('请输入密码'))
  } else if (value.length < 6 || value.length > 20) {
    callback(new Error('密码长度在 6 到 20 个字符'))
  } else {
    callback()
  }
}

export const validateConfirmPassword = (password: string) => {
  return (rule: any, value: string, callback: any) => {
    if (value === '') {
      callback(new Error('请再次输入密码'))
    } else if (value !== password) {
      callback(new Error('两次输入密码不一致'))
    } else {
      callback()
    }
  }
}

export const validateUsername = (rule: any, value: string, callback: any) => {
  if (value === '') {
    callback(new Error('请输入用户名'))
  } else if (value.length < 3 || value.length > 20) {
    callback(new Error('用户名长度在 3 到 20 个字符'))
  } else {
    callback()
  }
}

export const validateNickname = (rule: any, value: string, callback: any) => {
  if (value === '') {
    callback(new Error('请输入昵称'))
  } else if (value.length < 2 || value.length > 20) {
    callback(new Error('昵称长度在 2 到 20 个字符'))
  } else {
    callback()
  }
} 